const o = {
    method() {
        return "Hello!";
    }
};
// 等同于
const o1 = {
    method: function () {
        return "Hello!";
    }
};
const cart = {
    _wheels: 4,

    get wheels() {
        return this._wheels;
    },

    set wheels(value) {
        if (value < this._wheels) {
            throw new Error('数值太小了！');
        }
        this._wheels = value;
    }
}

lastWord = 'last word';
const a = {
    'first word': 'hello',//等同于['first word']: 'hello'
    [lastWord]: 'world'//如果[]里面是变量则需要赋值一个字符串
};
console.log(a['first word']);

let obj = {
    ['hello']() {
        return 'hi';
    }
};

console.log(obj.hello());  // hi

const keyA = [1, 2]
const keyB = { b: 2 };
const myObject = {
    [keyA]: 'valueA',//属性名表达式如果是一个数组，默认情况下会自动将数组转化为字符串
    [keyB]: 'valueB'//属性名表达式如果是一个对象，默认情况下会自动将对象转为字符串[object Object]
};
console.log(myObject);//{ '{name:1}': 'valueA', '[object Object]': 'valueB' }

const proto = {
    x: 'hello',
    foo() {
        console.log(this.x);

    },
};

const obj1 = {
    x: 'world',
    foo() {
        super.foo();
    }
}

Object.setPrototypeOf(obj, proto);

obj.foo() // 输出是"hello" 阮一峰说错了

